package com.gxa.meiye.admin.controller.zy;

import com.gxa.meiye.admin.service.OrderService;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.pojo.domain.Order;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-21  10:17
 */
@RestController
@Api(value="订单",tags = "订单接口")
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @ApiOperation("查询订单")
    //查询订单
    @PostMapping("/select")
    public Map select(String phone){
        List<Order> list = orderService.list(phone);
        JsonResult jsonResult=new JsonResult();
        if (!StringUtils.isEmpty(list)){
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(list);
        }
        return jsonResult.getMap();
    }
//    //立即预约-待确定
//    @PostMapping("/subscribe")
//    public Map subscribe(String phone){
//        return  null;
//    }
//    //待支付
//    @PostMapping("/paid")
//    public Map paid(String orderNumber){
//        return  null;
//    }
    //支付成功
    @PostMapping("/successful")
    public Map successful(String orderNumber,String serialNumber){

        Integer update = orderService.update(orderNumber,serialNumber);
        JsonResult jsonResult=new JsonResult();
        if (update!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("已支付");
        }
        jsonResult.setCode("0");

        return  jsonResult.getMap();
    }
    //退款中
    @PostMapping("/refund")
    public Map refund(String orderNumber){
        Integer integer = orderService.updateRe(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("退款中");
        }
        return  jsonResult.getMap();
    }
    //取消退款
    @PostMapping("/Cancelrefund")
    public Map CancelRefund(String orderNumber){
        Integer integer = orderService.updateCancel(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("取消成功");
        }
        return  jsonResult.getMap();
    }
    //退款成功
    @PostMapping("/refundsuccessful")
    public Map refundSuccessful(String orderNumber){
        String s = orderService.selectLiuSui(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (StringUtils.isEmpty(s)){
            jsonResult.setCode("0");
            jsonResult.setMsg("查询失败");
            return  jsonResult.getMap();
        }
        jsonResult.setCode("1");
        jsonResult.setData(s);
        return  jsonResult.getMap();
    }
    //退款成功修改状态
    @PostMapping("/refundSuccessfulUpdate")
    public Map refundSuccessfulUpdate(String orderNumber){
        Integer integer = orderService.updateRefund(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("修改成功");
            return jsonResult.getMap();
        }
        jsonResult.setCode("0");
        jsonResult.setMsg("修改失败");
        return jsonResult.getMap();
    }
    //已取消订单
    @PostMapping("/Canceled")
    public Map Canceled(String orderNumber,String reason,String content){
        Integer integer = orderService.addCancel(orderNumber, reason, content);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            Integer cancel = orderService.Cancel(orderNumber);
            if (cancel!=0){
                jsonResult.setCode("1");
                jsonResult.setMsg("取消成功");
            }
        }
        return  jsonResult.getMap();
    }
    //美疗师电话
    @PostMapping("/meiPhone")
    public Map meiPhone(String orderNumber){
        String s = orderService.selectMeiPhone(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (!StringUtils.isEmpty(s)){
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(s);
        }
        return  jsonResult.getMap();
    }
    //评价
//    @PostMapping("/evaluate")
//    public Map evaluate(String orderNumber){
//        return  null;
//    }
//    //查看常用地址
//    @GetMapping("/address")
//    public Map selectAddress(String phone){return null;}

}
